GBML manual / Strings

string_pad_left

Adds fill in front of s until it is width characters long, so text lines up: string_pad_left("7", 3, "0") is "007" and string_pad_left("42", 5, " ") is " 42". Only the first character of fill is used. Text that is already long enough comes back as it was.

Syntax

string_pad_left(s, width, fill) -> string

Arguments

NameType
sstring
widthint
fillstring

Returns

string

Description

Adds fill in front of s until the text is width characters long, so text lines up. Use it for scores, clocks and tables.

Example

var score = string_pad_left("42", 5, " ");
var code = string_pad_left("7", 3, "0");

score is " 42" (three spaces and 42) and code is "007".

The small print

Cost

One pass over the text, at most as long as a string can be.

On the GBA

A string has a fixed amount of room - your project's Longest string setting (32 characters unless you changed it). If the padded result would not fit, it is quietly cut off at the end, no error, and the game carries on. A width of 0 or less, or text already width long, changes nothing. An empty fill pads with spaces. For a whole number written with zeros in front, string_digits does it in one step.

See also: string_pad_rightstring_digitsstring_repeatstring_length